using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace EuropeEngulfed.NET
{
    partial class InitiateCombatDialog : Form
    {
        bool selectingGSU;
        bool newBattle;
        bool shownForAttacker;
        bool retreatBeforeCombat;
        bool reinforceBeforeBattle;
        private struct GSUSelection
        {
            public GroundSupportUnit GSU;
            public bool groundSupporting;
        };
        private List<Block> attackerBlockList;
        private List<GSUSelection> attackerGSUList;
        private List<Block> defenderBlockList;
        private List<GSUSelection> defenderGSUList;
        private Dictionary<MapInfo.CountryID, int> countriesThatCanSpendSAForReinforceBeforeBattle;
        private SelectSpecialActionsToSpendDialog reinforceBattleDialog;

        public InitiateCombatDialog(MapInfo.RegionID battleRegion, IGameStateInfoProvider gameInfoProvider, GameController.playerType attacker, bool shownForAttacker, bool selectingGSU, bool afterReinforce) : this(battleRegion,gameInfoProvider,attacker,shownForAttacker,selectingGSU,afterReinforce,false,null,false)
        {

        }

        public InitiateCombatDialog(MapInfo.RegionID battleRegion, IGameStateInfoProvider gameInfoProvider, GameController.playerType attacker, bool shownForAttacker, bool selectingGSU, bool afterReinforce, bool breakThroughCombat, List<MapInfo.CountryID> listOfCountriesSpendingSA)
            : this(battleRegion, gameInfoProvider, attacker, shownForAttacker, selectingGSU, afterReinforce, breakThroughCombat, listOfCountriesSpendingSA, false)
        {

        }

        public InitiateCombatDialog(MapInfo.RegionID battleRegion, IGameStateInfoProvider gameInfoProvider, GameController.playerType attacker, bool shownForAttacker, bool selectingGSU, bool afterReinforce, bool breakThroughCombat, List<MapInfo.CountryID> listOfCountriesSpendingSA, bool assault)
        {
            InitializeComponent();
            if(assault)
                this.Text = "ASSAULT Battle in " + Enum.GetName(typeof(MapInfo.RegionID), battleRegion) + " - Select Ground Support Units to Ground Support/Dogfight";
            else
                this.Text = "Battle in " + Enum.GetName(typeof(MapInfo.RegionID), battleRegion) + " - Select Ground Support Units to Ground Support/Dogfight";
            newBattle = gameInfoProvider.IsNewBattle(battleRegion);
            this.shownForAttacker = shownForAttacker;
            this.retreatBeforeCombat = false;
            this.reinforceBeforeBattle = false;
            this.selectingGSU = selectingGSU;
            attackerGSUList = new List<GSUSelection>();
            defenderGSUList = new List<GSUSelection>();
            if(!shownForAttacker)
            {
                this.Controls.Add(this.OkButton);
            }
            else
            {
                if(selectingGSU)
                    this.Controls.Add(this.OkButton);
                else
                {
                    this.Controls.Add(this.cancelButton);
                    this.Controls.Add(this.attackButton);
                    this.Controls.Add(this.assaultButton);
                }
                this.eyeButton.Visible = false;
            }
            if (attacker == GameController.playerType.AlliedPlayer)
            {
                if(breakThroughCombat)
                {
                    attackerBlockList = new List<Block>();
                    foreach (Block block in gameInfoProvider.GetRegionsAlliedBlockList(battleRegion))
                    {
                        if (listOfCountriesSpendingSA.Contains(block.CountryOwner) || (listOfCountriesSpendingSA.Contains(MapInfo.CountryID.USA) && block.CountryOwner == MapInfo.CountryID.FreeFrance))
                            attackerBlockList.Add(block);
                    }
                }
                else
                    attackerBlockList = gameInfoProvider.GetRegionsAlliedBlockList(battleRegion);
                foreach (GroundSupportUnit GSU in gameInfoProvider.GetRegionsAlliedGSUList(battleRegion))
                {
                    if (!GSU.OutOfSupply)
                    {
                        GSUSelection gsuSelection = new GSUSelection();
                        gsuSelection.GSU = GSU;
                        gsuSelection.groundSupporting = false;
                        if (breakThroughCombat)
                        {
                            if (listOfCountriesSpendingSA.Contains(gsuSelection.GSU.CountryOwner) || (listOfCountriesSpendingSA.Contains(MapInfo.CountryID.USA) && gsuSelection.GSU.CountryOwner == MapInfo.CountryID.FreeFrance))
                                attackerGSUList.Add(gsuSelection);
                        }
                        else
                            attackerGSUList.Add(gsuSelection);
                    }
                }
                defenderBlockList = gameInfoProvider.GetRegionsAxisBlockList(battleRegion);
                foreach (GroundSupportUnit GSU in gameInfoProvider.GetRegionsAxisGSUList(battleRegion))
                {
                    if(!GSU.OutOfSupply)
                    {
                        GSUSelection gsuSelection = new GSUSelection();
                        gsuSelection.GSU = GSU;
                        gsuSelection.groundSupporting = false;
                        defenderGSUList.Add(gsuSelection);
                    }
                }
            }
            else
            {
                defenderBlockList = gameInfoProvider.GetRegionsAlliedBlockList(battleRegion);
                foreach (GroundSupportUnit GSU in gameInfoProvider.GetRegionsAlliedGSUList(battleRegion))
                {
                    if (!GSU.OutOfSupply)
                    {
                        GSUSelection gsuSelection = new GSUSelection();
                        gsuSelection.GSU = GSU;
                        gsuSelection.groundSupporting = false;
                        defenderGSUList.Add(gsuSelection);
                    }
                }
                if (breakThroughCombat)
                {
                    attackerBlockList = new List<Block>();
                    foreach (Block block in gameInfoProvider.GetRegionsAxisBlockList(battleRegion))
                    {
                        if ((block.CountryOwner == MapInfo.CountryID.Italy && listOfCountriesSpendingSA.Contains(block.CountryOwner)) || (listOfCountriesSpendingSA.Contains(MapInfo.CountryID.Germany) && block.CountryOwner != MapInfo.CountryID.Italy))
                            attackerBlockList.Add(block);
                    }
                }
                else
                    attackerBlockList = gameInfoProvider.GetRegionsAxisBlockList(battleRegion);
                foreach (GroundSupportUnit GSU in gameInfoProvider.GetRegionsAxisGSUList(battleRegion))
                {
                    if (!GSU.OutOfSupply)
                    {
                        GSUSelection gsuSelection = new GSUSelection();
                        gsuSelection.GSU = GSU;
                        gsuSelection.groundSupporting = false;
                        if(breakThroughCombat)
                        {
                            if ((gsuSelection.GSU.CountryOwner == MapInfo.CountryID.Italy && listOfCountriesSpendingSA.Contains(gsuSelection.GSU.CountryOwner)) || (listOfCountriesSpendingSA.Contains(MapInfo.CountryID.Germany) && gsuSelection.GSU.CountryOwner != MapInfo.CountryID.Italy))
                                attackerGSUList.Add(gsuSelection);
                        }
                        else
                            attackerGSUList.Add(gsuSelection);
                    }
                }
            }

            if(!shownForAttacker)
            {
                bool SAForRetreatPresent = false;
                List<MapInfo.CountryID> listOfCountriesPresent = new List<MapInfo.CountryID>();
                foreach(Block block in defenderBlockList)
                {
                    if (!listOfCountriesPresent.Contains(MapInfo.GetEquivalentSupportCountry(block.CountryOwner)))
                        listOfCountriesPresent.Add(MapInfo.GetEquivalentSupportCountry(block.CountryOwner));
                }

                foreach (MapInfo.CountryID country in listOfCountriesPresent)
                {
                    if (MapInfo.IsMajorPower(country) && gameInfoProvider.GetNumSpecialActions(country) > 0) //Only major power special actions can be spent to retreat before combat...see 9.64
                        SAForRetreatPresent = true;
                }

                if (SAForRetreatPresent && !afterReinforce)
                {
                    this.Controls.Add(this.retreatBeforeCombatButton);
                    this.OkButton.Location = new Point(447, 569);
                }

                countriesThatCanSpendSAForReinforceBeforeBattle = GetNumSpecialActionsThatCanBeSpentByCountryForReinforceBeforeBattle(gameInfoProvider, battleRegion, attacker == GameController.playerType.AlliedPlayer ? GameController.playerType.AxisPlayer : GameController.playerType.AlliedPlayer);
                if(countriesThatCanSpendSAForReinforceBeforeBattle.Count > 0 && !afterReinforce)
                {
                    this.retreatBeforeCombatButton.Location = new Point(153, 569);
                    this.OkButton.Location = new Point(520, 569);
                    this.Controls.Add(this.reinforceBattleBattleButton);
                }
            }

            if (attackerGSUList.Count <= 0)
                this.attackerGSUListView.Visible = false;
            if (defenderGSUList.Count <= 0)
                this.defenderGSUListView.Visible = false;

            this.attackerBlocksListView.View = View.Tile;
            this.attackerBlocksListView.TileSize = new Size(PlayingPieceGraphics.GetBlockSize().Width * 2, PlayingPieceGraphics.GetBlockSize().Height * 2);
            foreach (Block attackingBlock in attackerBlockList)
            {
                this.attackerBlocksListView.Items.Add(attackingBlock.GetDescription());
            }

            this.defenderBlocksListView.View = View.Tile;
            this.defenderBlocksListView.TileSize = new Size(PlayingPieceGraphics.GetBlockSize().Width * 2, PlayingPieceGraphics.GetBlockSize().Height * 2);
            foreach (Block defendingBlock in defenderBlockList)
            {
                this.defenderBlocksListView.Items.Add(defendingBlock.GetDescription());
            }

            this.attackerGSUListView.View = View.Tile;
            this.attackerGSUListView.TileSize = new Size(PlayingPieceGraphics.GetGSUSize().Width + PlayingPieceGraphics.GetGSUSize().Width / 3, PlayingPieceGraphics.GetGSUSize().Height + PlayingPieceGraphics.GetGSUSize().Height / 3);
            foreach (GSUSelection attackingGSU in attackerGSUList)
            {
                this.attackerGSUListView.Items.Add(attackingGSU.GSU.GetDescription());
            }

            this.defenderGSUListView.View = View.Tile;
            this.defenderGSUListView.TileSize = new Size(PlayingPieceGraphics.GetGSUSize().Width + PlayingPieceGraphics.GetGSUSize().Width / 3, PlayingPieceGraphics.GetGSUSize().Height + PlayingPieceGraphics.GetGSUSize().Height / 3);
            foreach (GSUSelection defendingGSU in defenderGSUList)
            {
                this.defenderGSUListView.Items.Add(defendingGSU.GSU.GetDescription());
            }

            this.battleIcons.SetBattleIcons(gameInfoProvider, battleRegion, false);
        }

        private Dictionary<MapInfo.CountryID, int> GetNumSpecialActionsThatCanBeSpentByCountryForReinforceBeforeBattle(IGameStateInfoProvider gameInfoProvider, MapInfo.RegionID battleRegion, GameController.playerType reinforcingPlayer)
        {
            Dictionary<MapInfo.CountryID, int> countriesToReturn = new Dictionary<MapInfo.CountryID, int>();
            Dictionary<MapInfo.CountryID, int> specialActionsAvailable = new Dictionary<MapInfo.CountryID, int>();

            if(reinforcingPlayer == GameController.playerType.AxisPlayer)
            {
                specialActionsAvailable.Add(MapInfo.CountryID.Germany, gameInfoProvider.GetNumSpecialActions(MapInfo.CountryID.Germany));
                specialActionsAvailable.Add(MapInfo.CountryID.Italy, gameInfoProvider.GetNumSpecialActions(MapInfo.CountryID.Italy));
            }
            else
            {
                specialActionsAvailable.Add(MapInfo.CountryID.France, gameInfoProvider.GetNumSpecialActions(MapInfo.CountryID.France));
                specialActionsAvailable.Add(MapInfo.CountryID.GreatBritain, gameInfoProvider.GetNumSpecialActions(MapInfo.CountryID.GreatBritain));
                specialActionsAvailable.Add(MapInfo.CountryID.USSR, gameInfoProvider.GetNumSpecialActions(MapInfo.CountryID.USSR));
                specialActionsAvailable.Add(MapInfo.CountryID.USA, gameInfoProvider.GetNumSpecialActions(MapInfo.CountryID.USA));
                specialActionsAvailable.Add(MapInfo.CountryID.Poland, gameInfoProvider.GetNumSpecialActions(MapInfo.CountryID.Poland));
                specialActionsAvailable.Add(MapInfo.CountryID.Spain, gameInfoProvider.GetNumSpecialActions(MapInfo.CountryID.Spain));
                specialActionsAvailable.Add(MapInfo.CountryID.Turkey, gameInfoProvider.GetNumSpecialActions(MapInfo.CountryID.Turkey));
                specialActionsAvailable.Add(MapInfo.CountryID.Yugoslavia, gameInfoProvider.GetNumSpecialActions(MapInfo.CountryID.Yugoslavia));
            }

            foreach (Edge<Region, Adjacency> edge in MapInfo.GetEdgesFromRegion(battleRegion))
            {
                if(edge.Data is LandToLandAdjacency)
                {
                    if(((LandToLandAdjacency)edge.Data).ConnectionType != LandToLandAdjacency.LandConnectionType.AirConnection)
                    {
                        MapInfo.RegionID otherRegion = edge.Start.RegionID != battleRegion ? edge.Start.RegionID : edge.End.RegionID;
                        bool isContested = reinforcingPlayer == GameController.playerType.AlliedPlayer ? gameInfoProvider.GetRegionsAxisBlockList(otherRegion).Count > 0 : gameInfoProvider.GetRegionsAlliedBlockList(otherRegion).Count > 0;
                        if(!isContested)
                        {
                            List<GroundSupportUnit> listOfGSUToCheck = reinforcingPlayer == GameController.playerType.AlliedPlayer ? gameInfoProvider.GetRegionsAlliedGSUList(otherRegion) : gameInfoProvider.GetRegionsAxisGSUList(otherRegion);
                            List<Block> listOfBlocksToCheck = reinforcingPlayer == GameController.playerType.AlliedPlayer ? gameInfoProvider.GetRegionsAlliedBlockList(otherRegion) : gameInfoProvider.GetRegionsAxisBlockList(otherRegion);
                            Dictionary<MapInfo.CountryID, int> numBlocksPerCountry = new Dictionary<MapInfo.CountryID, int>();

                            foreach(Block block in listOfBlocksToCheck)
                            {
                                if (!block.Moved)
                                {
                                    if (numBlocksPerCountry.ContainsKey(MapInfo.GetEquivalentSupportCountry(block.CountryOwner)))
                                        numBlocksPerCountry[MapInfo.GetEquivalentSupportCountry(block.CountryOwner)]++;
                                    else
                                        numBlocksPerCountry.Add(MapInfo.GetEquivalentSupportCountry(block.CountryOwner), 1);
                                }
                            }

                            foreach(GroundSupportUnit GSU in listOfGSUToCheck)
                            {
                                if (!GSU.Moved)
                                {
                                    if (!numBlocksPerCountry.ContainsKey(MapInfo.GetEquivalentSupportCountry(GSU.CountryOwner)))
                                        numBlocksPerCountry.Add(MapInfo.GetEquivalentSupportCountry(GSU.CountryOwner), 1);
                                }
                            }

                            foreach(MapInfo.CountryID country in numBlocksPerCountry.Keys)
                            {
                                if (specialActionsAvailable.ContainsKey(country))
                                {
                                    if (!countriesToReturn.ContainsKey(country))
                                    {
                                        int numBlocksThatCanReinforce = Math.Min(specialActionsAvailable[country], numBlocksPerCountry[country]);
                                        if (numBlocksThatCanReinforce > 0)
                                            countriesToReturn.Add(country, numBlocksThatCanReinforce);
                                    }
                                    else
                                    {
                                        countriesToReturn[country] = Math.Max(countriesToReturn[country], numBlocksPerCountry[country]);
                                        countriesToReturn[country] = Math.Min(specialActionsAvailable[country], countriesToReturn[country]);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return countriesToReturn;
        }

        public Dictionary<MapInfo.CountryID,int> GetGSUSelections()
        {
            Dictionary<MapInfo.CountryID,int> gsuSelectionsToReturn = new Dictionary<MapInfo.CountryID,int>();
            List<GSUSelection> gsuSelectionListToCheck = this.shownForAttacker ? attackerGSUList : defenderGSUList;

            foreach (GSUSelection gsuSelection in gsuSelectionListToCheck)
            {
                if(gsuSelectionsToReturn.ContainsKey(gsuSelection.GSU.CountryOwner))
                {
                    if (gsuSelection.groundSupporting)
                        gsuSelectionsToReturn[gsuSelection.GSU.CountryOwner]++;
                }
                else
                {
                    if (gsuSelection.groundSupporting)
                        gsuSelectionsToReturn.Add(gsuSelection.GSU.CountryOwner, 1);
                }
            }

            return gsuSelectionsToReturn;
        }

        private void defenderBlocksListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            if(!newBattle || !shownForAttacker)
                e.DrawText(TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter);
            PlayingPieceGraphics.PaintBlock(e.Graphics, defenderBlockList[e.ItemIndex], new Point(e.Bounds.Left + (e.Bounds.Width / 2), e.Bounds.Top + (e.Bounds.Height / 2)), 1, newBattle && shownForAttacker);
        }

        private void defenderGSUListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            if (!shownForAttacker && selectingGSU)
                PlayingPieceGraphics.PaintGSU(e.Graphics, defenderGSUList[e.ItemIndex].GSU, new Point(e.Bounds.Left + (e.Bounds.Width / 2), e.Bounds.Top + (e.Bounds.Height / 2)), !defenderGSUList[e.ItemIndex].groundSupporting);
            else
                PlayingPieceGraphics.PaintGSU(e.Graphics, defenderGSUList[e.ItemIndex].GSU, new Point(e.Bounds.Left + (e.Bounds.Width / 2), e.Bounds.Top + (e.Bounds.Height / 2)));
        }

        private void attackerBlocksListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            if(!newBattle || shownForAttacker)
                e.DrawText(TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter);
            PlayingPieceGraphics.PaintBlock(e.Graphics, attackerBlockList[e.ItemIndex], new Point(e.Bounds.Left + (e.Bounds.Width / 2), e.Bounds.Top + (e.Bounds.Height / 2)), 1, newBattle && !shownForAttacker);
        }

        private void attackerGSUListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            if (shownForAttacker && selectingGSU)
                PlayingPieceGraphics.PaintGSU(e.Graphics, attackerGSUList[e.ItemIndex].GSU, new Point(e.Bounds.Left + (e.Bounds.Width / 2), e.Bounds.Top + (e.Bounds.Height / 2)), !attackerGSUList[e.ItemIndex].groundSupporting);
            else
                PlayingPieceGraphics.PaintGSU(e.Graphics, attackerGSUList[e.ItemIndex].GSU, new Point(e.Bounds.Left + (e.Bounds.Width / 2), e.Bounds.Top + (e.Bounds.Height / 2)));
        }

        private void DoCancel()
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            DoCancel();
        }

        private void DoAttack()
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void attackButton_Click(object sender, EventArgs e)
        {
            DoAttack();
        }

        private void DoAssault()
        {
            this.DialogResult = DialogResult.Yes;
            this.Close();
        }

        private void assaultButton_Click(object sender, EventArgs e)
        {
            DoAssault();
        }

        private void DoOK()
        {
            this.DialogResult = DialogResult.Ignore;
            this.Close();
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            DoOK();
        }

        private void attackerGSUListView_MouseClick(object sender, MouseEventArgs e)
        {
            if(shownForAttacker && selectingGSU)
            {
                if (e.Button == MouseButtons.Left)
                {
                    int numGSUGroundSupporting = 0;
                    foreach (GSUSelection gsuSelection in attackerGSUList)
                    {
                        if (gsuSelection.groundSupporting)
                            numGSUGroundSupporting++;
                    }

                    try
                    {
                        //Can't toggle if there are already the maximum number of GSUs ground supporting (3)
                        if (attackerGSUListView.SelectedItems.Count > 0)
                        {
                            if (attackerGSUList[attackerGSUListView.SelectedItems[0].Index].groundSupporting || numGSUGroundSupporting < 3)
                            {
                                GSUSelection selectionToChange = attackerGSUList[attackerGSUListView.SelectedItems[0].Index];
                                selectionToChange.groundSupporting = !selectionToChange.groundSupporting;
                                attackerGSUList[attackerGSUListView.SelectedItems[0].Index] = selectionToChange;
                                attackerGSUListView.Invalidate();
                            }
                        }
                    }
                    catch(IndexOutOfRangeException)
                    {

                    }
                }
            }
        }

        private void defenderGSUListView_MouseClick(object sender, MouseEventArgs e)
        {
            if (!shownForAttacker && selectingGSU)
            {
                if (e.Button == MouseButtons.Left)
                {
                    int numGSUGroundSupporting = 0;
                    foreach (GSUSelection gsuSelection in defenderGSUList)
                    {
                        if (gsuSelection.groundSupporting)
                            numGSUGroundSupporting++;
                    }

                    //Can't toggle if there are already the maximum number of GSUs ground supporting (3)
                    if(defenderGSUList[defenderGSUListView.SelectedItems[0].Index].groundSupporting || numGSUGroundSupporting < 3)
                    {
                        GSUSelection selectionToChange = defenderGSUList[defenderGSUListView.SelectedItems[0].Index];
                        selectionToChange.groundSupporting = !selectionToChange.groundSupporting;
                        defenderGSUList[defenderGSUListView.SelectedItems[0].Index] = selectionToChange;
                        defenderGSUListView.Invalidate();
                    }
                }
            }
        }

        public bool RetreatBeforeCombat
        {
            get
            {
                return retreatBeforeCombat;
            }
        }

        public bool ReinforceBeforeBattle
        {
            get
            {
                return reinforceBeforeBattle;
            }
        }

        private void DoRetreatBeforeCombat()
        {
            this.retreatBeforeCombat = true;
            this.DialogResult = DialogResult.Ignore;
            this.Close();
        }

        private void retreatBeforeCombatButton_Click(object sender, EventArgs e)
        {
            DoRetreatBeforeCombat();
        }

        private void DoReinforce()
        {
            reinforceBattleDialog = new SelectSpecialActionsToSpendDialog(countriesThatCanSpendSAForReinforceBeforeBattle);
            reinforceBattleDialog.ShowDialog(this);
            this.reinforceBeforeBattle = true;
            this.DialogResult = DialogResult.Ignore;
            this.Close();
        }

        private void reinforceBattleBattleButton_Click(object sender, EventArgs e)
        {
            DoReinforce();
        }

        public Dictionary<MapInfo.CountryID,int> GetReinforcementSAsSpent()
        {
            return reinforceBattleDialog.GetSpecialActionsSelections();
        }

        private void InitiateCombatDialog_Shown(object sender, EventArgs e)
        {
            this.battleIcons.SetBattleIconVisibility();
        }

        private void eyeButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Retry;
            this.Close();
        }

        private void InitiateCombatDialog_KeyUp(object sender, KeyEventArgs e)
        {
            bool ctrlKeyDown = Control.ModifierKeys == Keys.Control;
            if(e.KeyCode == Keys.A)
            {
                if(ctrlKeyDown)
                {
                    if (this.Controls.Contains(this.assaultButton))
                    {
                        DoAssault();
                    }
                }
                else
                {
                    if (this.Controls.Contains(this.attackButton))
                    {
                        DoAttack();
                    }
                }
            }
            else if(e.KeyCode == Keys.Space)
            {
                if (this.Controls.Contains(this.cancelButton))
                {
                    DoCancel();
                }
            }
            else if(e.KeyCode == Keys.R)
            {
                if(ctrlKeyDown)
                {
                    if (this.Controls.Contains(this.retreatBeforeCombatButton))
                    {
                        DoRetreatBeforeCombat();
                    }
                }
                else
                {
                    if (this.Controls.Contains(this.reinforceBattleBattleButton))
                    {
                        DoReinforce();
                    }
                }
            }
            else if(e.KeyCode == Keys.Enter)
            {
                if (this.Controls.Contains(this.OkButton))
                {
                    DoOK();
                }
            }
        }
    }
}